/*
 * Copyright 2012 the original author or authors.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package org.chacha;

import java.io.IOException;

import org.chacha.config.Config;
import org.chacha.log.LogPrn;
import org.chacha.socket.server.NIOServer;
import org.chacha.task.TokenCleanTask;

/**
 * 
 *	@author: hejing
 *	@date: 2012-11-15-上午10:35:25
 */
public class ChachaServer {
    private static final LogPrn log = new LogPrn(ChachaServer.class);
    private static int serverPort=9001;
    private static String VERSION="0.1";
	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		serverPort=Config.getServerPort();
		NIOServer server=new NIOServer(serverPort);
		server.startServer();
		log.info("Chacha Server Listen On "+serverPort+",version:"+VERSION);
		Runtime.getRuntime().addShutdownHook(new ShutdownHook());
		TokenCleanTask tokenTask=new TokenCleanTask();
		tokenTask.startUp();
	}
	
    /**
     * Inner class that logs the shutdown.
     */
    public static class ShutdownHook extends Thread {
        public void run() {
        	log.info("Server exiting...");
        }
    }
}
